package com.nix.web.service.user;

import com.nix.web.databases.pojo.user.Permissions;
import com.nix.web.databases.pojo.user.Role;
import com.nix.web.databases.service.iteratory.Iterator;
import com.nix.web.databases.service.iteratory.ObjectAggregate;
import com.nix.web.databases.service.user.PermissionService;
import com.nix.web.service.constant.IsUseResources;
import org.springframework.stereotype.Service;




/**
 * Create by zhangpe0312@qq.com on 2017/12/16.
 */
@Service
public class PermissionServiceImpl extends PermissionService {
    /**
     * 返回一个包含了这个角色被冻结的权限的迭代器
     *
     * @param role
     * @return
     * @throws Exception
     */
    public Iterator getRoleFreezePermissionAllIterator(Role role) throws Exception {
        ObjectAggregate aggregate = new ObjectAggregate();
        aggregate.appends(getPermissionAllByRoleID(role.getId(), IsUseResources.Freeze));
        return aggregate.iterator();
    }

    /**
     * 返回一个包含了这个角色正常使用的权限的迭代器
     * @param role
     * @return
     * @throws Exception
     */
    public Iterator<Permissions> getRoleNormalPermissionAllIterator(Role role) throws Exception {
        ObjectAggregate<Permissions> aggregate = new ObjectAggregate();
        aggregate.appends(getPermissionAllByRoleID(role.getId(),IsUseResources.Normal));
        return aggregate.iterator();
    }

    /**
     * 返回这个角色的所有权限
     * 包括冻结或者未冻结的
     * @param role
     * @return
     * @throws Exception
     */
    public Iterator getRolePermissionAllIterator(Role role) throws Exception{
        ObjectAggregate aggregate = new ObjectAggregate();
        aggregate.appends(getPermissionAllByRoleID(role.getId(), IsUseResources.Freeze));
        aggregate.appends(getPermissionAllByRoleID(role.getId(),IsUseResources.Normal));
        return aggregate.iterator();
    }
}
